//#### AstroRecruitment
var AstroRecruitment = new Object();

AstroRecruitment.SubmitContactUs = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=contact_us',
        data: $("#contact_form").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "contact-us-done") {
                $('#notice').show('slow');
                $('#thanks').show('slow');
                $('#enquiries').hide('slow');
            }
        },
        error: function () {
            $('#notice').show('slow');
            $('#notice').addClass('redwarning');
            $('#notice').text('Error');
        }
    });
}

AstroRecruitment.JobApply = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=jobapply',
        data: $("#job_application_form").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "appled") {
                $.colorbox.close();
                $("#job_application_name").val(null);
                $("#job_application_email").val(null);
                $("#job_application_telephone").val(null);
                $("#job_application_comment").val(null);
                $("#job_application_cv").val(null);

                $('#notice').text('Job application successfully sent');
                $('#notice').show('slow');
            }
            else if (response == "require-cv") {
                alert('Cv file name must be set');
            }
        },
        error: function () {

        }
    });
}

AstroRecruitment.EmailFriend = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=emailfriend',
        data: $("#send_friend_form").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "emailed") {
                $.colorbox.close();
                $("#send_to_friend_from_email").val(null);
                $("#send_to_friend_to_email").val(null);
                $("#send_to_friend_comment").val(null);

                $('#notice').text('Email successfully sent');
                $('#notice').show('slow');
            }
        },
        error: function () {

        }
    });
}

AstroRecruitment.ReferFriend = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=referfriend',
        data: $("#refer_friend_form").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "refered") {
                $.colorbox.close();
                $("#job_reference_name").val(null);
                $("#job_reference_email").val(null);
                $("#job_reference_comment").val(null);
                $("#job_reference_telephone").val(null);

                $('#notice').text('Recommend a friend successfully sent');
                $('#notice').show('slow');
            }
        },
        error: function () {

        }
    });
}

AstroRecruitment.ForgotPassword = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=forgotpassword',
        data: $("#forgot_password_form").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "sent-forgot-password") {
                $("#user_email").val(null);
                $('#notice').show('slow');
            }
            else {
            }
        },
        error: function () {

        }
    });
}

AstroRecruitment.SignIn = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=signin',
        data: $("#signin_form").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "successfull") {
                window.location = '/pages/account';
            }
            else {
                $('#notice').hide();
                $('#notice').show('slow');
            }
        },
        error: function () {

        }
    });
}

AstroRecruitment.ChangePassword = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=change-password',
        data: $("#change_password").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "successfull") {
                $("#user_current_password").val(null);
                $("#user_password").val(null);
                $("#user_password_confirmation").val(null);
                window.location = '/pages/account';
            }
            else {
                $('#currentinvalid').hide();
                $('#currentinvalid').show('slow');
            }
        },
        error: function () {

        }
    });
}

AstroRecruitment.Register = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=register',
        data: $("#register_form").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "registed") {
                $('#email_duplicated').hide();
                window.location = '/pages/account';
            }
            else if (response == "require-cv") {
                alert('Cv file name must be set');
            }
            else if (response == "email-duplicated") {
                $('#email_duplicated').hide();
                $('#email_duplicated').show('slow');
                $('#user_email').focus();
            }
        },
        error: function () {

        }
    });
}

AstroRecruitment.EditAccount = function (url) {
    $.ajax({
        type: "POST",
        url: url + '?command=edit-account',
        data: $("#edit_user").serialize(),
        success: function (transport) {
            var response = transport || "no response text";
            if (response == "updated") {
                window.location = '/pages/account';
            }
            else if (response == "require-cv") {
                alert('Cv file name must be set');
            }
            else if (response == "email-duplicated") {
                $('#email_duplicated').hide();
                $('#email_duplicated').show('slow');
                $('#user_email').focus();
            }
        },
        error: function () {

        }
    });
}